import 'package:flutter/material.dart';
// import 'package:get/get.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:pass_log/app/core/utils/adapt.dart';
import 'package:pass_log/app/data/services/theme_service.dart';

class TypeItem extends StatelessWidget {
  final Map<String, dynamic> item;
  final void Function(Map<String, dynamic>) onEdit;
  final void Function(Map<String, dynamic>) onDelete;
  const TypeItem({
    super.key,
    required this.item,
    required this.onEdit,
    required this.onDelete,
  });

  @override
  Widget build(BuildContext context) {
    return Slidable(
      // 右侧滑动菜单
      endActionPane: ActionPane(
        motion: const ScrollMotion(),
        children: [
          SlidableAction(
            onPressed: (BuildContext context) => onEdit(item),
            backgroundColor: item["id"] != "defaultType" ? const Color(0xFF7BC043) : Colors.grey,
            foregroundColor: item["id"] != "defaultType" ? Colors.white : Colors.white.withOpacity(0.5),
            icon: Icons.edit_document,
            label: 'Edit',
          ),
          SlidableAction(
            onPressed: (BuildContext context) => onDelete(item),
            backgroundColor: item["id"] != "defaultType" ? const Color(0xFFFE4A49) : Colors.grey,
            foregroundColor: item["id"] != "defaultType" ? Colors.white : Colors.white.withOpacity(0.5),
            icon: Icons.delete,
            label: 'Delete',
          ),
        ],
      ),
      // 列表项
      child: ListTile(
        leading: Container(
          height: Adapt.pt(36),
          width: Adapt.pt(36),
          decoration: BoxDecoration(
            color: ThemeService.to.curColorScheme.primaryContainer,
            shape: BoxShape.circle,
          ),
          child: Icon(IconData(int.parse(item["icon"]), fontFamily: item["fontFamily"])),
        ),
        title: Text(
          item["name"],
          style: TextStyle(
            color: ThemeService.to.curColorScheme.onPrimaryContainer,
            fontSize: Adapt.pt(18),
          ),
        ),
        trailing: const Icon(Icons.menu_rounded),
      ),
    );
  }
}
